package mysql

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"sync"
)

var (
	DB   *gorm.DB
	err  error
	once sync.Once
)

func InitMysql() {
	dsn := "root:root@tcp(127.0.0.1:3306)/2206a?charset=utf8mb4&parseTime=True&loc=Local"

	once.Do(func() {
		DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	})

	if err != nil {
		fmt.Println("数据库链接失败")
		return
	}
	fmt.Println("数据库链接成功")
	DB.AutoMigrate(&Doctor{})

}
